<% layout('/layouts/default.html', {title: '${plate.title}', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<#form:form id="inputForm" model="${plate}" action="${ctx}/storage/plate/save" method="post" class="form-horizontal">
		<div class="box-body">
			<div class="form-unit">${text('基本信息')}</div>
			<#form:hidden path="id"/>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required ">*</span> ${text('标题')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:input path="title" maxlength="255" class="form-control required"/>
						</div>
					</div>
				</div>
			</div>
				<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required hide">*</span> ${text('子标题')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:input path="subTitle" maxlength="255" class="form-control"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							${text('类型')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<% var types = [{type:'活动'},{type:'栏目'}]; %>
							<#form:select path="type" class="form-control" items="${types}" itemLabel="type" itemValue="type" blankOption="true" blankOptionLabel="请选择"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required hide">*</span> ${text('营销活动')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:listselect path="activityId" labelPath="activity.name" title="活动选择" url="${ctx}/storage/activity/select" allowClear="true" checkbox="false" itemCode="id" itemName="name"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required hide">*</span> ${text('栏目')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:listselect path="routeId" labelPath="route.name" title="栏目选择" url="${ctx}/storage/route/select" allowClear="true" checkbox="false" itemCode="id" itemName="name"/>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="box-footer">
			<div class="row">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
					<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
				</div>
			</div>
		</div>
		<div class="box-body">
			<h4 class="form-unit">
				${text('推广列表')}
			</h4>
			<div class="ml10 mr10">
				<table id="plateItemDataGrid"></table>
				<a href="${ctx}/storage/plate/item/form?plateId=${plate.id}" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
			</div>
		</div>
	</#form:form>
</div>
</div>
<% } %>
<script>
	$("#inputForm").validate({
		submitHandler: function(form){
			js.ajaxSubmitForm($(form), function(data){
				js.showMessage(data.message);
				if(data.result == Global.TRUE){
					js.closeCurrentTabPage(function(contentWindow){
						contentWindow.page();
					});
				}
			}, "json");
		}
	});
</script>
<script>
	//初始化板块项DataGrid对象
	$("#plateItemDataGrid").dataGrid({
		url: "${ctx}/storage/plate/item/listData",
		postData:"plateId=${plate.id}",
		// 设置数据表格列
		columnModel: [
			{header:'主键', name:'id', editable:true, hidden:true},
			{header:'${text("顺序")}', name:'sort', index:'a.sort', width:80, align:"center"},
			{header:'${text("缩略图")}', name:'thumbnail', index:'a.thumbnail', width:110, align:"center",formatter: function(val, obj, row, act){
					return '<img src="' + val + '" style="width: 98px;height: 52px"/>';
				}},
			{header:'${text("类型")}', name:'type', index:'a.type', width:80, align:"center"},
			{header:'${text("营销活动")}', name:'activity.name', index:'a.activity.name', width:150, formatter: function(val, obj, row, act){
					return row.activity ? row.activity.name : "";
				}},
			{header:'${text("栏目")}', name:'route.name', index:'a.route.name', width:150, formatter: function(val, obj, row, act){
				return row.route ? row.route.name : "";
			}},
			{header:'${text("商品")}', name:'goods.name', index:'a.goods.name', width:150, formatter: function(val, obj, row, act){
					return row.goods ? row.goods.name : "";
				}},
			{header:'${text("操作")}', name:'actions', width:120, sortable:false, fixed:true, formatter: function(val, obj, row, act){
					var actions = [];
					actions.push('<a href="${ctx}/storage/plate/item/form?id='+row.id+'" class="btnList" title="${text("编辑推广表")}"><i class="fa fa-pencil"></i>编辑</a>&nbsp;');
					actions.push('<a href="${ctx}/storage/plate/item/delete?id='+row.id+'" class="btnList" title="${text("删除推广表")}" data-confirm="${text("确认要删除该推广表吗？")}"><i class="fa fa-trash-o"></i>删除</a>&nbsp;');
					return actions.join('');
				}, editoptions: {defaultValue: 'new'}}
		]
	});
</script>
<script>
	function chanageType(){
		$("[name='activityId']").parents(".row").hide();
		$("[name='routeId']").parents(".row").hide();
		switch ($("#type option:selected").val()) {
			case "活动":
				$("[name='activityId']").parents(".row").show();
				break;
			case "栏目":
				$("[name='routeId']").parents(".row").show();
				break;
		}
	}
	$(function () {
		$(document).on("change","#type",function () {
			chanageType();
		});
		chanageType();
	});
</script>